/**
 * Convert touch position to node local position
 * @param touchPos 
 * @param node 
 * @param nodeCam 
 * @returns 
 */
export const ConvertTouchToNode = function (touchPos: cc.Vec2, node: cc.Node, nodeCam: cc.Camera) {
    return node.convertToNodeSpaceAR(nodeCam.getScreenToWorldPoint(touchPos));
};
/**
 * Convert a position in node to the position in nodeTo in same camera view
 * @param node 
 * @param nodeTo 
 */
export const ConvertNodeToNode = function (node: cc.Node, nodeTo: cc.Node) {
    return nodeTo.convertToNodeSpaceAR(node.parent.convertToWorldSpaceAR(node.getPosition()));
};
/**
 * Convert a position in node to the position in nodeTo by camera
 * @param node 
 * @param nodeCam 
 * @param nodeTo 
 * @param toCam 
 */
export const ConvertNodeToNodeByCamera = function (node: cc.Node, nodeCam: cc.Camera, nodeTo: cc.Node, toCam?: cc.Camera) {
    if (!toCam) toCam = nodeCam;
    return nodeTo.convertToNodeSpaceAR(toCam.getScreenToWorldPoint(nodeCam.getWorldToScreenPoint(node.convertToWorldSpaceAR(cc.v2()))));
};
/**
 * return points in "node" coordinate system
 * @param node 
 */
export const GetNodePoints = function (node: cc.Node, border: number = 0) {
    let contentSize = node.getContentSize();
    let anchorPoint = node.getAnchorPoint();
    let topLeft = cc.v2(-anchorPoint.x * contentSize.width + border, (1 - anchorPoint.y) * contentSize.height - border);
    let topRight = cc.v2((1 - anchorPoint.x) * contentSize.width - border, (1 - anchorPoint.y) * contentSize.height - border);
    let btmLeft = cc.v2(-anchorPoint.x * contentSize.width + border, -anchorPoint.y * contentSize.height + border);
    let btmRight = cc.v2((1 - anchorPoint.x) * contentSize.width - border, -anchorPoint.y * contentSize.height + border);
    return [topLeft, topRight, btmRight, btmLeft];
}